<?
class TagCloud
	{
		var $nMaxFontSize;
		var $nMinFontSize;
		var $aTags; // Array { TagName ,  Tag quantity , Tag Key }
		var $cUrl;
		var $cClassContainer = 'body';
		var $cTagValueName = 'tag';

	function setTagValueName( $cTagValueName)
		{
			$this->cTagValueName = $cTagValueName;
		}
	function setClassContainer( $cClassContainer)
		{
			$this->cClassContainer = strtolower($cClassContainer);
		}
	function TagCloud( $aTags,  $cUrl = '', $nMaxFontSize = 250, $nMinFontSize = 100)
		{
			$this->aTags = $aTags;
			$this->cUrl = $cUrl;
			$this->nMaxFontSize = $nMaxFontSize;
			$this->nMinFontSize = $nMinFontSize;
		}
	function make()
		{
			// Busca el maximo y minimo valor
			$nMinValue = 99999; $nMaxValue = 0;
			foreach ($this->aTags as $aTag )
			{
				$nValue = $aTag[1];
				if  ( $nValue < $nMinValue ) $nMinValue = $nValue;
				if  ( $nValue > $nMaxValue ) $nMaxValue = $nValue;
			}
			$nRango = ( $nMaxValue == $nMinValue) ? 1 : $nMaxValue - $nMinValue;
			// Obtiene el salto de las font por cada cantidad en el tag
			$nStep = ($this->nMaxFontSize - $this->nMinFontSize) / ($nRango);
			// Loop por cada tag
			foreach ($this->aTags as $aTag )
			{
				list( $cTag, $nValue, $cKey ) = $aTag;
				$nSize = $this->nMinFontSize + (($nValue - $nMinValue) * $nStep);
				$cTag = str_replace( '&', '&amp;', $cTag);
				if ( $this->cUrl )
				{
					if ( MODO_AJAX == true	)
						$cUrl = ' href="javascript:void(0);"  onclick=\'send( "' . $this->cUrl . "&amp;" . $this->cTagValueName . "=$cKey\", refreshElement, \"" . $this->cClassContainer . "\");'  ";
					else
						$cUrl = ' href="' . $this->cUrl . "&amp;" . $this->cTagValueName . "=$cKey\" ";

				}
				$cReturn .=  " <a $cUrl style=\"font-size: $nSize%\" title=\"$cTag tiene $nValue\" >". $cTag. "</a> ";
			}
			return $cReturn;
		}
	}
?>